package com.gw.service.impl;

import com.gw.context.BaseContext;
import com.gw.mapper.PostMapper;
import com.gw.mapper.UserMapper;
import com.gw.pojo.dto.PostSADTO;
import com.gw.pojo.dto.UserUpdateDTO;
import com.gw.pojo.entity.User;
import com.gw.pojo.vo.PostSAVO;
import com.gw.pojo.vo.UserVO;
import com.gw.service.AdminService;
import com.gw.service.PostSAService;
import com.gw.service.PostService;
import io.swagger.models.properties.EmailProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private PostSAService postSAService;
    @Autowired
    private PostMapper postMapper;


    @Override
    public UserVO changeUserIdentityByEmail(String email,int identity) {
        User user = userMapper.getByEmail(email);
        user.setIdentity(identity);
        userMapper.updateUser(user);

        return UserVO.builder()
                .sex(user.getSex())
                .email(user.getEmail())
                .nickname(user.getNickname())
                .studentId(user.getStudentId())
                .phone(user.getPhone())
                .grades(user.getGrades())
                .name(user.getName())
                .avatar(user.getAvatar())
                .build();
    }

    @Override
    public UserVO getUserByEmail(String email) {
        User user = userMapper.getByEmail(email);
        UserVO userVO=UserVO.builder()
                .sex(user.getSex())
                .studentId(user.getStudentId())
                .phone(user.getPhone())
                .grades(user.getGrades())
                .avatar(user.getAvatar())
                .nickname(user.getNickname())
                .name(user.getName())
                .email(user.getEmail())
                .build();
        return userVO;
    }

    @Override
    public PostSAVO addPostSA(PostSADTO postSADTO) {
        return postSAService.addPost(postSADTO);
    }

    @Override
    public void deletePostSA(Long id) {
        postSAService.deletePost(id);
    }

    @Override
    public void deletePost(Long id) {
        postMapper.deleteById(id);
    }


}
